
//*******************************************************重写RadioGroup****************************************	    
				Ext.override(Ext.form.RadioGroup, {     
				    getValue: function(){     
				        var v;     
				        if (this.rendered) {     
				            this.items.each(function(item){     
				                if (!item.getValue())      
				                    return true;     
				                v = item.getRawValue();     
				                return false;     
				            });     
				        }     
				        else {     
				            for (var k in this.items) {     
				                if (this.items[k].checked) {     
				                    v = this.items[k].inputValue;     
				                    break;     
				                }     
				            }     
				        }
				        
				        return v;     
				    },     
				    setValue: function(v){     
				        if (this.rendered)      
				            this.items.each(function(item){     
				                item.setValue(item.getRawValue() == v);   
				            });     
				        else {     
				            for (var k in this.items) {     
				                this.items[k].checked = this.items[k].inputValue == v;     
				            }     
				        } 
				        
				    }     
				}); 

/** **************** 新增报表方法 ******************* */
				function add_table_fun(fparentBh, fparentName, tree_op) {

					var table_form = new top.Ext.form.FormPanel(
							{
								frame : true,
								url : 'reportInfo!saveReportInfo.do',
								method : 'POST',
								labelWidth : 80,
								waitMsgTarget : true,
								items : [{
											fieldLabel : '当前操作',
											html : '在' + fparentName + '下新增节点'
										}, new top.Ext.form.RadioGroup({
						                       id:'type_radio_id',
											   style:'width:180px; display: block;text-align:left;line-height:22px;',
											   height:20,
						       				   fieldLabel : '节点类型',
						                       columns : 3,
						                       vertical :true,
						                       items:[
						                              {boxLabel:'报表',inputValue:'1',name:'ftype',checked: true},
						                              {boxLabel:'报表类别',inputValue:'2',name:'ftype'}],
										        listeners : {
										        	'change' : function(rg, checked){
										        		sqlContent.getEl().dom.readOnly = checked.getGroupValue() == 'yes' ? false : true;
												}}
									    }),
										{
											xtype : 'textfield',
											fieldLabel : '报表编号',
											name : 'fbh',
											readOnly : false,
											allowBlank : true,
											emptyText : '',
											blankText : '',
											width : 200
										}, {
											xtype : 'textfield',
											fieldLabel : '报表名称',
											name : 'fname',
											readOnly : false,
											allowBlank : true,
											emptyText : '',
											blankText : '',
											width : 200
										}, {
											xtype : 'textfield',
											fieldLabel : '报表附名',
											name : 'fname_next',
											readOnly : false,
											allowBlank : true,
											emptyText : '',
											blankText : '',
											width : 200
										}, {
											xtype : 'textfield',
											fieldLabel : '责任人',
											name : 'fzrr',
											readOnly : false,
											allowBlank : true,
											emptyText : '',
											blankText : '',
											width : 200
										}, {
											xtype : 'textfield',
											fieldLabel : '制表人',
											name : 'fzbr',
											readOnly : false,
											allowBlank : true,
											emptyText : '',
											blankText : '',
											width : 200
										}, {
											xtype : 'textarea',
											fieldLabel : '备注',
											name : 'fdesc',
											readOnly : false,
											allowBlank : true,
											height : 40,
											width : 290
										}, {
											xtype : 'hidden',
											name : 'fflag',
											value : '1' //报表
										}, {
											xtype : 'hidden',
											name : 'fparent',
											value : fparentBh
										}]
							});

							
					var btn_sure_add_table = new top.Ext.Button({
						text : '确定',
						iconCls : 'sy-save',
						handler : function() {
							var frm = table_form.getForm();
							/*var ccgc=frm.findField("ccgc_radio_id");
							var pflag='';
							ccgc.eachItem(function(item){  
							    if(item.checked===true){  
							        if(item.inputValue==2){
							        	pflag='y';
							        }  
							    }  
							});*/
							if (frm.isValid()) {
								frm.submit({
									waitTitle : '请稍候',
									waitMsg : '正在提交表单数据,请稍候...',
									success : function(form, action) {
										add_table_window.close();
										tree_op.root.reload();
										top.Ext.Msg.alert('', '保存成功！');
										
									},
									failure : function(form, action) {
										add_table_window.close();
										tree_op.root.reload();
										top.Ext.Msg.alert('', '保存失败！');
									},// failure
									icon : Ext.Msg.ERROR
								});
							};// isValid
						}
					});
					
					var btn_cancel_add_table = new top.Ext.Button({
						text : '取消',
						iconCls : 'sy-reset',
						handler : function() {
							add_table_window.close();
						}
					});
							
					var add_table_window = new top.Ext.Window(
							{
								width : 420,
								height : 350,
								layout : 'fit', 
								title : '新增报表',
								iconCls : 'sy-win-flag',
								modal : true,
								tbar : [ btn_sure_add_table, '-', btn_cancel_add_table ],
								items : [ table_form ]
							});
					add_table_window.show();

				} // end add_td_fun()				
				
/** **************** 新增报表方法 ******************* */
				function mod_table_fun(fbh, fname, tree_op) {

					var table_form = new top.Ext.form.FormPanel(
							{
								frame : true,
								url : 'reportInfo!updateReportInfo.do',
								method : 'POST',
								labelWidth : 80,
								waitMsgTarget : true,
								items : [{
											fieldLabel : '当前操作',
											html : '修改报表' + fname 
										}, {
											xtype : 'textfield',
											fieldLabel : '报表名称',
											name : 'fname',
											readOnly : false,
											allowBlank : true,
											emptyText : '',
											blankText : '',
											width : 200
										}, {
											xtype : 'textfield',
											fieldLabel : '报表附名',
											name : 'fname_next',
											readOnly : false,
											allowBlank : true,
											emptyText : '',
											blankText : '',
											width : 200
										}, {
											xtype : 'textfield',
											fieldLabel : '责任人',
											name : 'fzrr',
											readOnly : false,
											allowBlank : true,
											emptyText : '',
											blankText : '',
											width : 200
										}, {
											xtype : 'textfield',
											fieldLabel : '制表人',
											name : 'fzbr',
											readOnly : false,
											allowBlank : true,
											emptyText : '',
											blankText : '',
											width : 200
										}, {
											xtype : 'textarea',
											fieldLabel : '备注',
											name : 'fdesc',
											readOnly : false,
											allowBlank : true,
											height : 40,
											width : 290
										}, {
											xtype : 'hidden',
											name : 'fbh',
											value : fbh
										}]
							});

							
					var btn_sure_mod_table = new top.Ext.Button({
						text : '确定',
						iconCls : 'sy-save',
						handler : function() {
						var frm = table_form.getForm();
							if (frm.isValid()) {
								frm.submit({
									waitTitle : '请稍候',
									waitMsg : '正在提交表单数据,请稍候...',
									success : function(form, action) {
										mod_table_window.close();
										tree_op.root.reload();
										top.Ext.Msg.alert('', '保存成功！');
										
									},
									failure : function(form, action) {
										mod_table_window.close();
										tree_op.root.reload();
										top.Ext.Msg.alert('', '保存失败！');
									},// failure
									icon : Ext.Msg.ERROR
								});
							};// isValid
						}
					});
					
					var btn_cancel_mod_table = new top.Ext.Button({
						text : '取消',
						iconCls : 'sy-reset',
						handler : function() {
							mod_table_window.close();
						}
					});
							
					var mod_table_window = new top.Ext.Window(
							{
								width : 420,
								height : 400,
								layout : 'fit', 
								title : '修改报表',
								iconCls : 'sy-win-flag',
								modal : true,
								tbar : [ btn_sure_mod_table, '-', btn_cancel_mod_table ],
								items : [ table_form ]
							});
					mod_table_window.show();

				} // end add_td_fun()
				
				
				
/** ************************************************ 设计报表 ******************************************************************* */
				
function design_table_fun(fbh, fname, tree_op) {

	var Tree_design = top.Ext.tree;
	var loader_design = new Tree_design.TreeLoader({
		dataUrl : 'headInfo!findTableHeadTree.do'
	});
	loader_design.on("beforeload", function(treeLoader, node) {
		loader_design.baseParams.fflag = "1";//报表类型树
		loader_design.baseParams.fbh = fbh;
		//loader.baseParams.fcode  = node.attributes.fcode;
	}, this);

	loader_design.processResponse = function(response, node, callback) {
		var json1 = response.responseText;
		try {
			var json = eval("(" + json1 + ")");
			node.beginUpdate();
			//从json中取得json数组
			var o = json["key"];
			for ( var i = 0, len = o.length; i < len; i++) {
				var n = this.createNode(o[i]);
				if (n) {
					node.appendChild(n);
				}
			}
			node.endUpdate();
			if (typeof callback == "function") {
				callback(this, node);
			}
		} catch (e) {
			this.handleFailure(response);
		}
	};

	var tree_design = new Tree_design.TreePanel({
		region : 'center',
		id : 'west-panel',
		width : 280,
		//	title : '所属区县',
		useArrows : true,
		autoScroll : true,
		animate : true,
		enableDD : true,
		containerScroll : true,
		rootVisible : false, //树根不可见
		loader : loader_design
	});

	//单击事件
	tree_design.on('click', function(node) {
		//alert(node.attributes.ftype);
		top.Ext.getCmp("head_type_radio_id").setValue(node.attributes.fleaf);
		top.Ext.getCmp("col_type_radio_id").setValue(node.attributes.ftype);
		top.Ext.get("fcoldesc_id_design").dom.value = node.attributes.text;
		top.Ext.getCmp("tbfx_radio_id").setValue(node.attributes.ftbfx);
		if(node.attributes.faccuracy == null) {
			top.Ext.get("faccuracy_id_design").dom.value = "";
		} else {
			top.Ext.get("faccuracy_id_design").dom.value = node.attributes.faccuracy;
		}
		
		if(node.attributes.fsum == "1") {
			top.Ext.getCmp("sum_radio_id").setValue(node.attributes.fsum);
		} else {
			top.Ext.getCmp("sum_radio_id").setValue("2");
		}
		if(node.attributes.fzq == "1") {
			top.Ext.getCmp("zq_radio_id").setValue(node.attributes.fzq);
		} else {
			top.Ext.getCmp("zq_radio_id").setValue("2");
		}
		if(node.attributes.fzqsd == null || node.attributes.fzqsd == "null") {
			top.Ext.get("fzqsd_id_design").dom.value = "";
		} else {
			top.Ext.get("fzqsd_id_design").dom.value = node.attributes.fzqsd;
		}
		if(node.attributes.fcolor == null || node.attributes.fcolor == "null") {
			top.Ext.get("fcolor_id_design").dom.value = "";
		} else {
			top.Ext.get("fcolor_id_design").dom.value = node.attributes.fcolor;
		}
		if(node.attributes.fdesc == null || node.attributes.fdesc == "null") {
			top.Ext.get("fdesc_id_design").dom.value = "";
		} else {
			top.Ext.get("fdesc_id_design").dom.value = node.attributes.fdesc;
		}
		
		top.Ext.get("fparent_id_design").dom.value = node.attributes.id;
		top.Ext.get("fbh_id_design").dom.value = node.attributes.fbh;
		top.Ext.get("fid_id_design").dom.value = node.attributes.id;
	}, tree_design);

	// set the root node
	var root_design = new Tree_design.AsyncTreeNode({
		text : '所有报表',
		draggable : false,
		id : '0',
		fbh : fbh,
		ftype : '1'
	});
	tree_design.setRootNode(root_design);
	//root_design.expand();					
				
	var head_type_Radio = new top.Ext.form.RadioGroup({
                       id:'head_type_radio_id',
					   style:'width:100px; display: block;text-align:left;line-height:22px;',
					   height:20,
					   width:240,
       				   fieldLabel : '列类型',
                       columns : 3,
                       vertical :true,
                       items:[
                              {boxLabel:'静态列',inputValue:'2',name:'fleaf',checked: true},
                              {boxLabel:'取数列',inputValue:'1',name:'fleaf'}],
				        listeners : {
				        	'change' : function(rg, checked){
				        		sqlContent.getEl().dom.readOnly = checked.getGroupValue() == 'yes' ? false : true;
						}}
			    });
			    
	var type_Radio = new top.Ext.form.RadioGroup({
                       id:'col_type_radio_id',
					   style:'width:100px; display: block;text-align:left;line-height:22px;',
					   height:20,
					   width:220,
       				   fieldLabel : '取值类型',
                       columns : 4,
                       vertical :true,
                       items:[
                              {boxLabel:'文本',inputValue:'1',name:'ftype',checked: true},
                              {boxLabel:'数字',inputValue:'2',name:'ftype'},
                              {boxLabel:'日期',inputValue:'3',name:'ftype'}],
				        listeners : {
				        	'change' : function(rg, checked){
				        		sqlContent.getEl().dom.readOnly = checked.getGroupValue() == 'yes' ? false : true;
						}}
			    });
			    
	var sum_Radio = new top.Ext.form.RadioGroup({
                       id:'sum_radio_id',
					   style:'width:100px; display: block;text-align:left;line-height:22px;',
					   height:20,
					   width:220,
       				   fieldLabel : '参与统计',
                       columns : 3,
                       vertical :true,
                       items:[
                              {boxLabel:'是',inputValue:'1',name:'fsum'},
                              {boxLabel:'否',inputValue:'2',name:'fsum',checked: true} ],
				        listeners : {
				        	'change' : function(rg, checked){
				        		sqlContent.getEl().dom.readOnly = checked.getGroupValue() == 'yes' ? false : true;
						}}
			    });
			    
	var zq_Radio = new top.Ext.form.RadioGroup({
               id:'zq_radio_id',
			   style:'width:100px; display: block;text-align:left;line-height:22px;',
			   height:20,
			   width:220,
			   fieldLabel : '数据钻取',
               columns : 3,
               vertical :true,
               items:[
                      {boxLabel:'是',inputValue:'1',name:'fzq'},
                      {boxLabel:'否',inputValue:'2',name:'fzq',checked: true} ],
		        listeners : {
		        	'change' : function(rg, checked){
		        		sqlContent.getEl().dom.readOnly = checked.getGroupValue() == 'yes' ? false : true;
				}}
	    });
			    
    var tbfx_Radio = new top.Ext.form.RadioGroup({
           id:'tbfx_radio_id',
		   style:'width:100px; display: block;text-align:left;line-height:22px;',
		   height:20,
		   width:220,
		   fieldLabel : '图表分析',
           columns : 3,
           vertical :true,
           items:[
                  {boxLabel:'是',inputValue:'1',name:'ftbfx'},
                  {boxLabel:'否',inputValue:'2',name:'ftbfx',checked: true} ],
	        listeners : {
	        	'change' : function(rg, checked){
	        		sqlContent.getEl().dom.readOnly = checked.getGroupValue() == 'yes' ? false : true;
			}}
    });
			    
	var table_head_form = new top.Ext.form.FormPanel(
	{
		frame : true,
		url : 'headInfo!addTableHead.do',
		method : 'POST',
		labelWidth : 60,
		labelAlign : 'right',
		waitMsgTarget : true,
		items : [ head_type_Radio, type_Radio, {
					xtype : 'textfield',
					fieldLabel : '列名称',
					name : 'fcoldesc',
					id : 'fcoldesc_id_design',
					readOnly : false,
					allowBlank : true,
					emptyText : '',
					blankText : '',
					width : 200
				}, {
					xtype : 'numberfield',
					fieldLabel : '精度',
					name : 'faccuracy',
					id : 'faccuracy_id_design',
					readOnly : false,
					allowBlank : true,
					emptyText : '',
					blankText : '',
					width : 200
				}, sum_Radio, zq_Radio, {
					xtype : 'numberfield',
					fieldLabel : '钻取深度',
					name : 'fzqsd',
					id : 'fzqsd_id_design',
					readOnly : false,
					allowBlank : true,
					emptyText : '',
					blankText : '',
					width : 200
				}, tbfx_Radio, {
					xtype : 'numberfield',
					fieldLabel : '图表颜色',
					name : 'fcolor',
					id : 'fcolor_id_design',
					readOnly : false,
					allowBlank : true,
					emptyText : '',
					blankText : '',
					width : 200
				}, {
					xtype : 'textarea',
					fieldLabel : '备注',
					name : 'fdesc',
					id : 'fdesc_id_design',
					readOnly : false,
					allowBlank : true,
					height : 40,
					width : 240
				}, {
					xtype : 'hidden',
					name : 'fbh',
					id : 'fbh_id_design',
					value : fbh
				}, {
					xtype : 'hidden',
					name : 'fparent',
					id : 'fparent_id_design',
					value : fbh
				}, {
					xtype : 'hidden',
					id : 'fid_id_design',
					name : 'fid'
				}]
	});

							
	var btn_add_design = new top.Ext.Button({
		text : '新增',
		iconCls : 'sy-add',
		handler : function() {
		var frm = table_head_form.getForm();
			if (frm.isValid()) {
				frm.submit({
					waitTitle : '请稍候',
					waitMsg : '正在提交表单数据,请稍候...',
					success : function(form, action) {
						tree_design.root.reload();
						top.Ext.Msg.alert('', '保存成功！');
						
					},
					failure : function(form, action) {
						tree_design.root.reload();
						top.Ext.Msg.alert('', '保存失败！');
					},// failure
					icon : Ext.Msg.ERROR
				});
			};// isValid
		}
	});
	
	var btn_mod_design = new top.Ext.Button({
		text : '修改',
		iconCls : 'sy-sure',
		handler : function() {
		var frm = table_form.getForm();
			if (frm.isValid()) {
				frm.submit({
					waitTitle : '请稍候',
					waitMsg : '正在提交表单数据,请稍候...',
					success : function(form, action) {
						mod_table_window.close();
						tree_op.root.reload();
						top.Ext.Msg.alert('', '保存成功！');
						
					},
					failure : function(form, action) {
						mod_table_window.close();
						tree_op.root.reload();
						top.Ext.Msg.alert('', '保存失败！');
					},// failure
					icon : Ext.Msg.ERROR
				});
			};// isValid
		}
	});
	
	var btn_delete_design = new top.Ext.Button({
		text : '删除',
		iconCls : 'sy-delete',
		handler : function() {
		var frm = table_form.getForm();
			if (frm.isValid()) {
				frm.submit({
					waitTitle : '请稍候',
					waitMsg : '正在提交表单数据,请稍候...',
					success : function(form, action) {
						mod_table_window.close();
						tree_op.root.reload();
						top.Ext.Msg.alert('', '保存成功！');
						
					},
					failure : function(form, action) {
						mod_table_window.close();
						tree_op.root.reload();
						top.Ext.Msg.alert('', '保存失败！');
					},// failure
					icon : Ext.Msg.ERROR
				});
			};// isValid
		}
	});
					
	var btn_cancel_design = new top.Ext.Button({
		text : '关闭',
		iconCls : 'sy-cancel',
		handler : function() {
			design_table_window.close();
		}
	});
	
	
	
	
	var tree_nav = new top.Ext.Panel({
		title : '报表树',
		region : 'west',
		split : true,
		layoutConfig:{
            animate:true
        },
		width : 290,
		layout : 'fit',
		autoScroll : false,
		collapsible : true,
		items : [ tree_design ]
	});	
 		    
    var design_rightPanel = new top.Ext.Panel({
    	region: "center",
		layout:'fit',
		border : true,
		//title : '表头',
	    //collapsible : true,
		margins:'0 5 0 0',
		tbar : [btn_add_design, '-', btn_mod_design, '-', btn_delete_design, '-', btn_cancel_design],
	    items : [table_head_form]
	});
 			
	var design_table_window = new top.Ext.Window(
	{
		width : 680,
		height : 500,
		layout : 'border',
		title : '设计报表头部信息',
		iconCls : 'sy-win-flag',
		modal : true,
		items : [ tree_nav, design_rightPanel ]
	});
	design_table_window.show();

} // end add_td_fun()